package com.ruoyi.project.oms.paeaAuPoint.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.oms.paeaAuPoint.domain.PaeaAuPoint;
import com.ruoyi.project.oms.paeaAuPoint.service.IPaeaAuPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 监督点定义Controller
 *
 * @author 关晓强
 * @date 2020-03-14
 */
@Controller
@RequestMapping("/oms/paeaAuPoint")
public class PaeaAuPointController extends BaseController
{
    private String prefix = "oms/paeaAuPoint";

    @Autowired
    private IPaeaAuPointService paeaAuPointService;

    @RequiresPermissions("oms:paeaAuPoint:view")
    @GetMapping()
    public String paeaAuPoint()
    {
        return prefix + "/paeaAuPoint";
    }

    /**
     * 查询监督点定义列表
     */
    @RequiresPermissions("oms:paeaAuPoint:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaAuPoint paeaAuPoint)
    {
        startPage();
        List<PaeaAuPoint> list = paeaAuPointService.list(new QueryWrapper<>(paeaAuPoint));
        return getDataTable(list);
    }

    /**
     * 导出监督点定义列表
     */
    @RequiresPermissions("oms:paeaAuPoint:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaAuPoint paeaAuPoint)
    {
        List<PaeaAuPoint> list = paeaAuPointService.list(new QueryWrapper<>(paeaAuPoint));
        ExcelUtil<PaeaAuPoint> util = new ExcelUtil<PaeaAuPoint>(PaeaAuPoint.class);
        return util.exportExcel(list, "paeaAuPoint");
    }

    /**
     * 新增监督点定义
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存监督点定义
     */
    @RequiresPermissions("oms:paeaAuPoint:add")
    @Log(title = "监督点定义", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaAuPoint paeaAuPoint)
    {
        return toAjax(paeaAuPointService.saveOrUpdate(paeaAuPoint));
    }

    /**
     * 修改监督点定义
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaAuPoint paeaAuPoint = paeaAuPointService.getById(id);
        mmap.put("paeaAuPoint", paeaAuPoint);
        return prefix + "/edit";
    }

    /**
     * 修改保存监督点定义
     */
    @RequiresPermissions("oms:paeaAuPoint:edit")
    @Log(title = "监督点定义", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaAuPoint paeaAuPoint)
    {
        return toAjax(paeaAuPointService.saveOrUpdate(paeaAuPoint));
    }

    /**
     * 删除监督点定义
     */
    @RequiresPermissions("oms:paeaAuPoint:remove")
    @Log(title = "监督点定义", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaAuPointService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 校验监督点代码
     */
    @PostMapping("/checkCodeUnique")
    @ResponseBody
    public String checkCodeUnique(PaeaAuPoint paeaAuPoint)
    {
        if(paeaAuPointService.getOne(new QueryWrapper<>(paeaAuPoint))!=null){
            return Constants.NOT_UNIQUE;
        }
        return Constants.UNIQUE;
    }
}
